<?
	include("../lib/config.php");
	
	$nik 	= $HTTP_GET_VARS['nik'];
	$op		= $HTTP_GET_VARS['op'];
	$no		= $HTTP_GET_VARS['no'];

	if($op == "edit"){
		$Faction = "../lib/update.php";
		$Vbutton = "Update";
		$sql	= "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY seqno) AS No, CONVERT(CHAR(12), tgl_efektif, 103) TglEfektif, CONVERT(CHAR(12), tgl_skd, 103) TglSKD, CONVERT(CHAR(12), tgl_selesai, 103) TglSelesai, * FROM VKarirPTSI WHERE NIK='".$nik."') SELECT * FROM limit WHERE No='$no'";
		$query	= mssql_query($sql,$conn);
		$row	= mssql_fetch_array($query);
		$Nama	= $row[Nama];
	}
	else{
		$Faction 	= "../lib/save.php";
		$Vbutton 	= "Save";
		$Nama		= $HTTP_GET_VARS['nama'];
	}
	include("../header.php");
?>
<script type="text/javascript">
	function LoadFocus(){
		document.forms[0].elements[0].focus();
	}
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){
		if(document.FEmployee.nik.value == "")
		{
			alert("Field : NIK tidak boleh kosong ...");
			document.FEmployee.nik.focus();
			return false;
		}

		if(document.FEmployee.no_surat.value == "")
		{
			alert("Field : No. Surat tidak boleh kosong ...");
			document.FEmployee.no_surat.focus();
			return false;
		}

		if(document.FEmployee.jenis_surat.value == "")
		{
			alert("Field : Jenis Surat tidak boleh kosong ...");
			document.FEmployee.jenis_surat.focus();
			return false;
		}

		if(document.FEmployee.tgl_efektif.value == "")
		{
			alert("Field : Tanggal Efektif tidak boleh kosong ...");
			document.FEmployee.tgl_efektif.focus();
			return false;
		}
		
		if(document.FEmployee.tgl_skd.value == "")
		{
			alert("Field : Tanggal SKD tidak boleh kosong ...");
			document.FEmployee.tgl_skd.focus();
			return false;
		}
		/*
		if(document.FEmployee.tgl_selesai.value == "")
		{
			alert("Field : Tanggal Selesai tidak boleh kosong ...");
			document.FEmployee.tgl_selesai.focus();
			return false;
		}
		*/
		if(document.FEmployee.seksi1.value == "")
		{
			alert("Field : Jabatan Utama: Unit Kerja tidak boleh kosong ...");
			document.FEmployee.seksi1.focus();
			return false;
		}

		if(document.FEmployee.lokasi1.value == "")
		{
			alert("Field : Jabatan Utama: Lokasi tidak boleh kosong ...");
			document.FEmployee.lokasi1.focus();
			return false;
		}

		if(document.FEmployee.jabatan1.value == "")
		{
			alert("Field : Jabatan Utama: Jabatan tidak boleh kosong ...");
			document.FEmployee.jabatan1.focus();
			return false;
		}

		if(document.FEmployee.fungsi1.value == "")
		{
			alert("Field : Jabatan Utama: Fungsional tidak boleh kosong ...");
			document.FEmployee.fungsi1.focus();
			return false;
		}

		if(document.FEmployee.gol1.value == "")
		{
			alert("Field : Jabatan Utama: Golongan tidak boleh kosong ...");
			document.FEmployee.gol1.focus();
			return false;
		}

		if(document.FEmployee.status_karyawan1.value == "")
		{
			alert("Field : Jabatan Utama: Status Karyawan tidak boleh kosong ...");
			document.FEmployee.status_karyawan1.focus();
			return false;
		}

		////////////////
		/*
		if(document.FEmployee.seksi2.value == "")
		{
			alert("Field : Jabatan Rangkap: Seksi tidak boleh kosong ...");
			document.FEmployee.seksi2.focus();
			return false;
		}

		if(document.FEmployee.lokasi2.value == "")
		{
			alert("Field : Jabatan Rangkap: Lokasi tidak boleh kosong ...");
			document.FEmployee.lokasi2.focus();
			return false;
		}

		if(document.FEmployee.jabatan2.value == "")
		{
			alert("Field : Jabatan Rangkap: Jabatan tidak boleh kosong ...");
			document.FEmployee.jabatan2.focus();
			return false;
		}

		if(document.FEmployee.fungsi2.value == "")
		{
			alert("Field : Jabatan Rangkap: Fungsiona tidak boleh kosong ...");
			document.FEmployee.fungsi2.focus();
			return false;
		}

		if(document.FEmployee.gol2.value == "")
		{
			alert("Field : Jabatan Rangkap: Golongan tidak boleh kosong ...");
			document.FEmployee.gol2.focus();
			return false;
		}

		if(document.FEmployee.status_karyawan2.value == "")
		{
			alert("Field : Jabatan Rangkap: Status Karyawan tidak boleh kosong ...");
			document.FEmployee.status_karyawan2.focus();
			return false;
		}
		*/
		
		document.FEmployee.submit();
		
	}
	
	function show_popup(page)
	{
		child = open
		(
			"frm_list_emp.php",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
</script>
</head>

<form name="FEmployee" action="<?=$Faction?>" method="post">
<table width="93%" class="table_indent2">
<tr>
 <td colspan="2" class="line_bottom">&nbsp;&nbsp;<b>Pengangkatan/Mutasi/Promosi/Demosi</b></td>
</tr>
</table>
<table style="position:relative; left:80px;">
<tr>
 <td colspan="2">
  <table>
   <tr>
    <td width="50">NIK</td>
	<td><input type="text" name="nik" readonly="" value="<?=$nik?>" />
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup()'><img src='../images/people.png' border=0></a>";
		}
	?>
	</td>
   </tr>
   <tr>
    <td>Nama</td>
	<td><input type="text" size="50" name="nama" value="<?=$Nama?>" readonly="" /></td>
   </tr>
  </table>
 </td>
</tr>
<tr>
 <td colspan="2"><hr noshade="noshade" size="-2" /></td>
</tr>
<tr>
 <td valign="top">
  <table>
   <tr>
    <td width="100">No. Surat</td>
	<td><input maxlength="50" type="text" name="no_surat" size="30" value="<?=$row[no_surat]?>" /> <span class="required">*</span></td>
   </tr>
   <tr>
    <td width="100">Jenis Surat</td>
	<td>
	<select name="jenis_surat">
	 <?
		//$sqlJS 	= mssql_query("SELECT * FROM VJenisSurat WHERE ",$conn);
	 ?>
	 <option value="">--Pilih--</option>
	 <?
	 	$sJS = mssql_query("SELECT * FROM VJenisSurat ORDER BY nama ASC",$conn);
	 	while($rJS = mssql_fetch_array($sJS)){
			if($rJS[IDCode] == $row[Jenis]){
			echo"<option value='$rJS[IDCode]' selected>$rJS[nama]</option>";
			}
			echo"<option value='$rJS[IDCode]'>$rJS[nama]</option>";
		}
	 ?>
	</select> <span class="required">*</span>
	</td>
   </tr>
   <tr>
    <td width="100">Tanggal Efektif</td>
	<td><input type="text" value="<?=$row[TglEfektif]?>" name="tgl_efektif" size="11" /> <span class="required">*</span><i> <a href="javascript:calA.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></td>
   </tr>
   <tr>
    <td width="100">Tanggal SKD</td>
	<td><input type="text" value="<?=$row[TglSKD]?>" name="tgl_skd" size="11" /> <span class="required">*</span><i> <a href="javascript:calB.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></td>
   </tr>
   <tr>
    <td width="100">Tanggal Selesai</td>
	<td><input type="text" value="<?=$row[TglSelesai]?>" name="tgl_selesai" size="11" /> &nbsp;&nbsp;<i> <a href="javascript:calC.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></td>
   </tr>
   <tr>
    <td colspan="2">
	 <fieldset ><legend><b>Jabatan Utama</b></legend>
	 <table>
	 <!--
	  <tr>
	   <td>Direktorat</td>
	   <td><input type="text" name="direktorat1" size="35" /></td>
	  </tr>
	  <tr>
	   <td>Koor. Teknis</td>
	   <td><input type="text" name="koor_teknis1" size="35" /></td>
	  </tr>
	  <tr>
	   <td>Divisi/Biro/Cabang</td>
	   <td><input type="text" name="divisi1" size="35" /></td>
	  </tr>
	  <tr>
	   <td>Bagian</td>
	   <td><input type="text" name="bagian1" size="35" /></td>
	  </tr>
	  -->
	  <tr>
	   <td>Unit Kerja</td>
	   <td>
	   <select name="seksi1" style="width:227px;">
	   <?
	   /*
	   	$sek1	= mssql_query("SELECT * FROM MstSO WHERE kode_so='$row[kode_so1]'",$conn);
		$rek1	= mssql_fetch_array($sek1);
		echo"<option value='$rek1[kode_so]'>$rek1[AreaCode] - $rek1[uraian]</option>";
		*/
	   ?>
	    <option value="">--Pilih--</option>
	   <?
	   	$sseksi1	= mssql_query("SELECT * FROM MstSO WHERE LevelSO='3' ORDER BY uraian ASC ",$conn);
		while($rseksi1 = mssql_fetch_array($sseksi1)){
			echo"<option value='$rseksi1[kode_so]'";
			if($row[kode_so1] == $rseksi1[kode_so]){
				echo" selected";
			}
			echo">$rseksi1[uraian]</option>";
		}
	   ?>
	   </select>
	   <span class="required">*</span></td>
	  </tr>
	  <tr>
	   <td>Lokasi</td>
	   <td>
	   <select name="lokasi1" style="width:227px;">
	   <?
	   	$sqlLok = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi = '$row[lokasi1]'",$conn);
		$rowLok = mssql_fetch_array($sqlLok);
		echo"<option value='$rowLok[kode_lokasi]'>$rowLok[propinsi] - $rowLok[distrik]</option>";
	   ?>
	    <option value="">--pilih--</option>
	   <?
	   		$sqlLokasi = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi LIKE 'D%' ORDER BY propinsi,distrik",$conn);
			while($rowLokasi = mssql_fetch_array($sqlLokasi)){
				echo"<option value='$rowLokasi[kode_lokasi]'>$rowLokasi[propinsi] - $rowLokasi[distrik]</option>";
			}
	   ?>
	   </select> <span class="required">*</span>
	   </td>
	  </tr>
	  <tr>
	   <td>Jabatan</td>
	   <td>
	   <select name="jabatan1" style="width:227px;">
	    <?
			$getJ1 = mssql_query("SELECT * FROM MstJabatan WHERE kode='$row[jabatan1]' ",$conn);
			$rowJ1 = mssql_fetch_array($getJ1);
			echo"<option value='$rowJ1[kode]'>$rowJ1[jabatan]</option>";
		?>
	    <option value="">--Pilih--</option>
		<?
			$sJab = mssql_query("SELECT * FROM MstJabatan ORDER BY jabatan ASC",$conn);
			while($rJab = mssql_fetch_array($sJab)){
				echo"<option value='$rJab[kode]'>$rJab[jabatan]</option>";
			}
		?>
	   </select> <span class="required">*</span>
	   </td>
	  </tr>
	  <tr>
	   <td>Fungsional</td>
	   <td>
	   <select name="fungsi1" style="width:227px;">
	   <?
	   	$fun1	= mssql_query("SELECT * FROM MstFungsional WHERE kode='$row[fungsi1]'",$conn);
		$run1	= mssql_fetch_array($fun1);
		echo"<option value='$run1[kode]'>$run1[nama]</option>";
	   ?>
	    <option value="">--Pilih--</option>
		<?
			$sFungsi = mssql_query("SELECT * FROM MstFungsional ORDER BY nama ASC",$conn);
			while($rFungsi = mssql_fetch_array($sFungsi)){
				echo"<option value='$rFungsi[kode]'>$rFungsi[nama]</option>";
			}
		?>
	   </select> <span class="required">*</span>
	   </td>
	  </tr>
	  <tr>
	   <td>Golongan</td>
	   <td>
		  <select name="gol1">
		   <option value="<?=$row[gol1]?>"><?=$row[gol1]?></option>
		   <option value="">--Pilih--</option>
			<?
				for($r=1;$r<=17;$r++){
					echo"<option value='$r'>$r</option>";
				}
			?>
		  </select> <span class="required">*</span>
	   </td>
	  </tr>
	  <tr>
	   <td>Status Karyawan</td>
	   <td>
	   <select name="status_karyawan1" style="width:227px;">
	   <?
	   	$sql_stat1 = mssql_query("SELECT * FROM VStatusKaryawan WHERE kode='$row[stat_kar1]'",$conn);
		$row_stat1 = mssql_fetch_array($sql_stat1);
		echo"<option value='$row_stat1[kode]'>$row_stat1[Nama]<option";
	   ?>
	   <option value="">--Pilih--</option>
	   <?
	   		$sql_stat	= mssql_query("SELECT * FROM VStatusKaryawan ORDER BY Nama",$conn);
			while($row_stat = mssql_fetch_array($sql_stat)){
				echo"<option value='$row_stat[kode]'>$row_stat[Nama]</option>";
			}
	   ?>
	   </select> <span class="required">*</span>
	   </td>
	  </tr>
	 </table>
	 </fieldset>
	</td>
   </tr>
  </table>
 </td>
 <td valign="top">
  <table border="0" width="100%">
   <tr>
    <td width="100">&nbsp;</td>
	<td>&nbsp;</td>
   </tr>
   <tr>
    <td width="100" valign="top">Keterangan</td>
	<td valign="top"><textarea cols="55" name="keterangan"><?=$row[keterangan]?></textarea></td>
   </tr>
   <tr>
    <td width="100">Kelompok</td>
	<td>
	<select name="kelompok">
	 <option value="">--pilih--</option>
	 <?
	 	$sk	= mssql_query("SELECT * FROM VKlpOperasional ORDER BY nama",$conn);
		while($rk = mssql_fetch_array($sk)){
			if($rk[kode] == ""){
			echo"<option value=''>--pilih--</option>";
			}
			elseif($rk[kode] == $row[kelompok]){
			echo"<option value='$rk[kode]' selected>$rk[nama]</option>";
			}
			echo"<option value='$rk[kode]'>$rk[nama]</option>";
		}
		
	 ?>
	</select>
	</td>
   </tr>
   <tr height="32">
    <td width="100">&nbsp;</td>
	<td></td>
   </tr>
   <tr>
    <td colspan="2" height="100" valign="top">
	 <fieldset><legend><b>Jabatan Rangkap</b></legend>
	 <table>
	 <!---
	  <tr>
	   <td>Direktorat</td>
	   <td><input type="text" name="direktorat2" size="35" /></td>
	  </tr>
	  <tr>
	   <td>Koor. Teknis</td>
	   <td><input type="text" name="koor_teknis2" size="35" /></td>
	  </tr>
	  <tr>
	   <td>Divisi/Biro/Cabang</td>
	   <td><input type="text" name="divisi2" size="35" /></td>
	  </tr>
	  <tr>
	   <td>Bagian</td>
	   <td><input type="text" name="bagian2" size="35" /></td>
	  </tr>
	  
	  <tr>
	   <td>Unit Kerja</td>
	   <td>
	   <select name="seksi2" style="width:227px;">
	   <?
	   	$sek2	= mssql_query("SELECT * FROM MstSO WHERE kode_so='$row[kode_so2]'",$conn);
		$rek2	= mssql_fetch_array($sek2);
		echo"<option value='$rek2[kode_so]'>$rek2[AreaCode] - $rek2[uraian]</option>";
	   ?>
	    <option value="">--Pilih--</option>
	   <?
	   	$sseksi2	= mssql_query("SELECT * FROM MstSO ORDER BY kode_so",$conn);
		while($rseksi2 = mssql_fetch_array($sseksi2)){
			echo"<option value='$rseksi2[kode_so]'>$rseksi2[AreaCode] - $rseksi2[uraian]</option>";
		}
	   ?>
	   </select>
	   </td>
	  </tr>
	  <tr>
	   <td>Lokasi</td>
	   <td>
	   <select name="lokasi2" style="width:227px;">
	   <?
	   	$sqlLok2 = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi = '$row[lokasi2]'",$conn);
		$rowLok2 = mssql_fetch_array($sqlLok2);
		echo"<option value='$rowLok2[kode_lokasi]'>$rowLok2[propinsi] - $rowLok2[distrik]</option>";
	   ?>
	    <option value="">--pilih--</option>
	   <?
	   		$sqlLokasi2 = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi LIKE 'D%' ORDER BY propinsi,distrik",$conn);
			while($rowLokasi2 = mssql_fetch_array($sqlLokasi2)){
				echo"<option value='$rowLokasi2[kode_lokasi]'>$rowLokasi2[propinsi] - $rowLokasi2[distrik]</option>";
			}
	   ?>
	   </select>
	   </td>
	  </tr>
	  -->
	  <tr>
	   <td>Jabatan</td>
	   <td>
	   <select name="jabatan2" style="width:227px;">
	    <?
			$getJ2 = mssql_query("SELECT * FROM MstJabatan WHERE kode='$row[jabatan2]' ",$conn);
			$rowJ2 = mssql_fetch_array($getJ2);
			echo"<option value='$rowJ2[kode]'>$rowJ2[jabatan]</option>";
		?>
	    <option value="">--Pilih--</option>
		<?
			$sJab2 = mssql_query("SELECT * FROM MstJabatan ORDER BY jabatan ASC",$conn);
			while($rJab2 = mssql_fetch_array($sJab2)){
				echo"<option value='$rJab2[kode]'>$rJab2[jabatan]</option>";
			}
		?>
	   </select>
	   </td>
	  </tr>
	  <tr>
	   <td>Fungsional</td>
	   <td>
	   <select name="fungsi2" style="width:227px;">
	   <?
	   	$fun2	= mssql_query("SELECT * FROM MstFungsional WHERE kode='$row[fungsi1]'",$conn);
		$run2	= mssql_fetch_array($fun2);
		echo"<option value='$run2[kode]'>$run2[nama]</option>";
	   ?>	   
	    <option value="">--Pilih--</option>
		<?
			$sFungsi2 = mssql_query("SELECT * FROM MstFungsional ORDER BY nama ASC",$conn);
			while($rFungsi2 = mssql_fetch_array($sFungsi2)){
				echo"<option value='$rFungsi2[kode]'>$rFungsi2[nama]</option>";
			}
		?>
	   </select>
	   </td>
	  </tr>
	  <!--
	  <tr>
	   <td>Golongan</td>
	   <td>
		  <select name="gol2">
		   <option value="<?=$row[gol2]?>"><?=$row[gol2]?></option>
		   <option value="">--Pilih--</option>
			<?
				for($r=1;$r<=15;$r++){
					echo"<option value='$r'>$r</option>";
				}
			?>
		  </select> <span class="required">*</span>
	   </td>
	  </tr>
	  <tr>
	   <td>Status Karyawan</td>
	   <td>
	   <select name="status_karyawan2" style="width:227px;">
	   <?
	   	$sql_stats = mssql_query("SELECT * FROM VStatusKaryawan WHERE kode='$row[stat_kar2]'",$conn);
		$row_stats = mssql_fetch_array($sql_stats);
		echo"<option value='$row_stats[kode]'>$row_stats[Nama]<option";
	   ?>
	   <option value="">--Pilih--</option>
	   <?
	   		$sql_stat	= mssql_query("SELECT * FROM VStatusKaryawan ORDER BY Nama",$conn);
			while($row_stat = mssql_fetch_array($sql_stat)){
				echo"<option value='$row_stat[kode]'>$row_stat[Nama]</option>";
			}
	   ?>
	   </select> <span class="required">*</span>
	   </td>
	  </tr>
	  -->
	 </table>
	 </fieldset>
	</td>
   </tr>
  </table>
 </td>
</tr>
<tr>
 <td colspan="2" align="right">
  <input type="hidden" name="cat" value="karir_ptsi" />
  <input type="hidden" name="no" value="<?=$row[No]?>" />
  <input type="button" value="Cancel" onclick="Javascript:history.back();" class="button" />  
  <input type="button" value="<?=$Vbutton?>" class="button" onclick="Javascript:Validate()" />
 </td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
 <td colspan="2" style="border:none;"><? include("../footer.php"); ?></td>
</tr>
</table>
<script type="text/javascript">

var f = document.forms[0];
MaskInput(f.tgl_efektif,"99/99/9999");
MaskInput(f.tgl_skd,"99/99/9999");
MaskInput(f.tgl_selesai,"99/99/9999");
//MaskInput(f.ipk,"999");
//]]>
</script>
<script type="text/javascript">
// script untuk popup calendar
	var calA = new calendar1(document.forms[0].elements['tgl_efektif']);
	calA.year_scroll = true;
	calA.time_comp = false;	
	var calB = new calendar1(document.forms[0].elements['tgl_skd']);
	calB.year_scroll = true;
	calB.time_comp = false;	
	var calC = new calendar1(document.forms[0].elements['tgl_selesai']);
	calC.year_scroll = true;
	calC.time_comp = false;	

</script>

</body>
</html>
